<template>
  <div
    class="node"
    :style="{ background: nodeData.child.length > 0 ? '#94aaeb' : '#f29d38' }"
    @click="clickNode(nodeData.code)"
  >
    <i
      class="el-icon-circle-plus-outline"
      v-if="nodeData.child.length > 0"
      @click="extendNode"
    ></i>
    <span>{{ nodeData.name }}</span>
  </div>
</template>

<script>
export default {
  name: "NodeList",
  props: {
    nodeData: {
      type: Object,
      default: {},
    },
  },
  methods: {
    extendNode() {
      this.$emit("extendNode", this.nodeData);
    },
    clickNode(code) {
      this.$emit("clickNode", code);
    }
  },
};
</script>

<style lang="scss" scoped>
.node {
  height: 48px;
  width: 160px;
  line-height: 48px;
  padding: 0 10px;
  text-align: center;
  white-space: nowrap;
  text-overflow: ellipsis;
  overflow: hidden;
  margin-bottom: 10px;
  border-radius: 4px;
  color: #fff;
  margin-right: 10px;
  cursor: default;
  &:hover {
    opacity: .8;
    cursor: pointer;
  }
  &:active {
    opacity: .9;
  }
  i {
    margin-right: 4px;
    font-size: 16px;
  }
}
</style>